import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { CommentService } from './comment.service';
import { CreateCommentDto } from './dto/create-comment.dto';
import { QueryCommentDto } from './dto/query-comment.dto';
import { RequireLogin, UserInfo } from 'src/custom.decorator';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiBearerAuth,
} from '@nestjs/swagger';

@ApiTags('评论管理')
@ApiBearerAuth()
@Controller('comment')
export class CommentController {
  constructor(private readonly commentService: CommentService) {}

  @Post()
  @RequireLogin()
  @ApiOperation({ summary: '发表评论' })
  @ApiResponse({ status: 201, description: '评论成功' })
  async create(
    @Body() createCommentDto: CreateCommentDto,
    @UserInfo('userId') userId: number,
  ) {
    return await this.commentService.create(createCommentDto, userId);
  }

  @Get()
  @ApiOperation({ summary: '查询评论列表' })
  async findAll(@Query() queryCommentDto: QueryCommentDto) {
    return await this.commentService.findAll(queryCommentDto);
  }
}
